﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Data;
using System.Globalization;
using System.Windows;

namespace BadHabit.WPFTools.Converters {
    public class EnumBooleanConverter : IValueConverter {

        #region IValueConverter Members



        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            
                        
            int parameterInt;
            if(!Int32.TryParse(parameter.ToString(), out parameterInt))
                return DependencyProperty.UnsetValue;

            int valueInt;
            if (!Int32.TryParse(value.ToString(), out valueInt))
                return DependencyProperty.UnsetValue;

            return (valueInt == parameterInt);

        }



        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            if (!(value is Boolean))
                return DependencyProperty.UnsetValue;
            if ((bool)value)
                return parameter;
            else
                return DependencyProperty.UnsetValue;
            

        }



        #endregion

    }


}
